package snafu.implementation.actions.drop.random;

import java.util.List;

import snafu.framework.actions.IntentionItself;
import snafu.framework.actions.IntentionView;
import snafu.framework.agents.AgentState;
import snafu.framework.objects.WorldObject;
import snafu.framework.view.Access;
import snafu.framework.worlds.WorldMap;
import snafu.implementation.states.literals.have.HaveLiteral;

public class RandomDropIntentionItself extends IntentionItself<RandomDropAction> implements RandomDropIntention {
	public RandomDropIntentionItself(Access privacy) {
		super(privacy);
	}

	@Override
	public RandomDropAction createAction(List<WorldObject> target) {
		return new RandomDropAction(target, this);
	}

	@Override
	public IntentionView<RandomDropAction> createView(Access access) {
		return new RandomDropIntentionView(Access.PRIVATE, this);
	}

	@Override
	protected boolean checkApplicability(WorldMap perception, AgentState agent, List<WorldObject> targets) {
		WorldObject target = targets.get(0);
		
		// get all have literals
		List<HaveLiteral> literals = agent.getLiterals(HaveLiteral.class);
		
		// check whether target is in inventory
		boolean contains = false;
		for (HaveLiteral literal : literals) {
			if (literal.getValue().equals(target)) {
				contains = true;
				break;
			}
		}
		
		return contains;
	}

}
